package com.peter.animatedliststatedrawabledemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;

import android.graphics.drawable.AnimatedStateListDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private static final int[] STATE_CHECKED = new int[]{android.R.attr.state_checked};
    private static final int[] STATE_UNCHECKED = new int[]{};


    boolean flag;
    //mImageView.setImageState中参数必须是int[]。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ImageView mImageView = (ImageView) findViewById(R.id.my_ImageView);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag) {
                    mImageView.setImageState(STATE_UNCHECKED, true);
                    flag = false;
                } else {
                    mImageView.setImageState(STATE_CHECKED, true);
                    flag = true;
                }
            }
        });
    }

    private void hello() {
        CheckWidgetAnimatedStateListDrawable c = new CheckWidgetAnimatedStateListDrawable(null,null,null);
    }


    public void setupRadioButton() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
            asl.addState(
                    new int[]{android.R.attr.state_checked},
                    AppCompatResources.getDrawable(this, R.drawable.blue_drawable),
                    R.id.checked);
            asl.addState(
                    new int[0],
                    AppCompatResources.getDrawable(this, R.drawable.blue_drawable),
                    R.id.unchecked);
            asl.addTransition(
                    R.id.unchecked,
                    R.id.checked,
                    AnimatedVectorDrawableCompat.create(this, R.drawable.blue_drawable),
                    false);
            asl.addTransition(
                    R.id.checked,
                    R.id.unchecked,
                    AnimatedVectorDrawableCompat.create(this, R.drawable.blue_drawable),
                    false);

        } else {
        }
    }


}